import React, { Component } from 'react'
import Pubsub from "pubsub-js"
import { subcate } from '../../apis/classify.js'
import {withRouter} from 'react-router-dom'
class content extends Component {
  state = {
    goods: []
  }
  componentDidMount() {
    Pubsub.subscribe("list_id", (_, id) => {
      subcate(id).then((ok) => {

        this.setState({
          goods: ok.subcate
        }, () => {
          // console.log(111, this.state.goods);
        })
      })
      // console.log(id)
    })
  }
  goods_id(id) {
    this.props.history.push({
      pathname:'/index/allgood',
      state:{
        id:id
      }
    })
    // console.log(id);
  }
  render() {
    return (
      <div className='content'>
        {
          this.state.goods.subcategory &&
          this.state.goods.subcategory.map((item, index) => {
            return (
              <div className="box" key={index}>
                <h3 className='title' >{item.name}</h3>
                <div className="list">
                  {
                    item.subNavs.map((item, index) => {
                      return (
                        <div className="item" key={index} onClick={() => { this.goods_id(item.id) }}>
                          <img src={item.pic} alt="" />
                          <div className="name">
                            {item.name}
                          </div>
                        </div>
                      )
                    })
                  }
                </div>
              </div>
            )
          })
        }
      </div>
    )
  }
}
export default withRouter(content)